#!/bin/bash
war_file=/var/lib/jenkins/workspace/mmall/target/mmall.war
TOMCAT_HOME1=/opt/huawei/tomcat1
TOMCAT_HOME2=/opt/huawei/tomcat2

function shutdownTomcat()
{
sh ${TOMCAT_HOME1}/bin/shutdown.sh
sh ${TOMCAT_HOME2}/bin/shutdown.sh
}

function deployTomcat()
{
if [ -f "$war_file" ];
then
    echo "War file exists, deploy and start the server1."

    rm -rf ${TOMCAT_HOME1}/webapps/mmall
    rm -f ${TOMCAT_HOME1}/webapps/mmall.war
    cp  ${war_file} ${TOMCAT_HOME1}/webapps/mmall.war

    echo "War file exists, deploy and start the server2."

    rm -rf ${TOMCAT_HOME2}/webapps/mmall
    rm -f ${TOMCAT_HOME2}/webapps/mmall.war
    mv  ${war_file} ${TOMCAT_HOME2}/webapps/mmall.war

else
    echo "War file not exists, restart the server."
fi
       }


function startup()
{
cd ${TOMCAT_HOME1}/bin
chmod 711 *.sh

sh ${TOMCAT_HOME1}/bin/startup.sh

cd ${TOMCAT_HOME2}/bin
chmod 711 *.sh

sh ${TOMCAT_HOME2}/bin/startup.sh
}

shutdownTomcat
deployTomcat
startup